package main

import (
	"fmt"
	"io/ioutil"
	"net/http"
	"net/url"
)

func main() {
	resp, err := http.Get("http://127.0.0.1:9090/xxx/?name=二狗&age=18")
	if err != nil {
		fmt.Println("get url failed, err: ", err)
		return
	}

	// 方式2:
	//data := url.Values{}
	//urlObj, _ := url.Parse("http://127.0.0.1:9090/xxx/")
	//data.Set("name", "二狗")
	//data.Set("age", "9000")
	//urlStr := data.Encode() // URL encode之后的url
	//fmt.Println(urlStr)
	//urlObj.RawQuery = urlStr
	//request, err := http.NewRequest("GET", urlObj.String(), nil)
	//resp, err := http.DefaultClient.Do(request)
	//if err != nil {
	//	fmt.Printf("get url failed, err: %v\n", err)
	//	return
	//}
	//defer resp.Body.Close()		// 一定要记得关闭

	// 把服务端返回数据读出来
	all, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		fmt.Printf("read resp.Body failed, err: %v\n", err)
		return
	}
	fmt.Println(string(all))
}
